<template>
	<view class="home">
		<component :is="currentComponent" ref="dom" />
	</view>
</template>
<script setup>
	const wechat = import.meta.env.VITE_WX_URL;
	const wechat_open = import.meta.env.VITE_WX_OPEN;

	import {
		loginWechat,
		index,
		userInfo
	} from "@/request/api";
	import Prove from "@/components/home/Prove.vue";
	import List from "@/components/home/List.vue";

	import useLogin from "@/hooks/useLogin.js";
	import useWechat from "@/hooks/useWechat.js";
	import useShare from "@/hooks/useShare.js";

	const {
		wxLogin
	} = useLogin();

	const {
		wxShare
	} = useWechat();
	const {
		shop_share,
		share_url
	} = useShare();
	import {
		onShow,
		onHide
	} from "@dcloudio/uni-app";
	import {
		ref,
		shallowRef
	} from "vue";

	const currentComponent = shallowRef();
	const dom = shallowRef();

	const getUserInfo = async () => {
		let {
			user
		} = await userInfo();
		let has_shop = user.has_shop;
		currentComponent.value = has_shop ? List : Prove;

		let invitation = user.invitation_code;

		if (!has_shop) return false;
		let nickname = user.nickname;
		let users_id = user.id;
		let link = `${share_url}?users_id=${users_id}&is_share=true&invitation=${invitation}`;
		wxShare({
			title: `${nickname}${shop_share.title}`,
			desc: shop_share.desc,
			link: link,
			imgUrl: shop_share.imgUrl
		});
		dom.value.getList ? dom.value.getList() : "";
	};
	onShow(async () => {
		await wxLogin();
		await getUserInfo();
	});
</script>

<style scoped lang="scss">
	.home {}
</style>